package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public PageResult<Activity> list(ActivityDto activityDto) {

        PageHelper.startPage(activityDto.getPage(), activityDto.getPageSize());
        List<Activity> activityList = activityMapper.list(activityDto);
        Page<Activity> p = (Page<Activity>) activityList;
        return new PageResult<>(p.getTotal(), p.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        activityMapper.deleteById( id);
    }

    @Override
    public void add(Activity activity) {
        activityMapper.add( activity);
    }

    @Override
    public Activity getById(Integer id) {
        Activity activity = activityMapper.getById(id);
        return activity;
    }

    @Override
    public void upDate(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.upDate( activity);
    }

    @Override
    public List<Activity> listByType(String type) {
        List<Activity> list = activityMapper.listByType(type);
        return list;
    }
}
